const { useRef, useEffect } = require("react");

const useDebounce2 = (fn, delay) => {
    const timer = useRef(null);

    useEffect(() => {
        return () => {
            clearTimeout(timer.current);
        }
    }, [])

    return (...args) => {
        clearTimeout(timer.current);
        timer.current = setTimeout(() => {
            fn(...args);
        }, delay)
    }
}

export default useDebounce2;